package com.itany.controller;

import com.github.pagehelper.PageInfo;
import com.itany.pojo.Book;
import com.itany.pojo.Examine;
import com.itany.pojo.Manager;
import com.itany.pojo.User;
import com.itany.service.ExamineService;
import com.itany.vo.ActionResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Description: 类的描述
 * Author: SJY
 * Date: 2021/08/31 15:22
 * Version: 1.0 版本信息
 */
@Controller
@RequestMapping("/examine")
public class ExamineController {
    @Autowired
    ExamineService examineService;

    @RequestMapping("/selectExamine")
    @ResponseBody
    public Map<String,Object> findAll(@RequestParam(defaultValue="1")Integer page,
                                      @RequestParam(defaultValue="10")Integer rows,HttpSession session){
        Manager user = (Manager) session.getAttribute("user");
        Integer supplierid = user.getSupplierid();
        Map<String,Object> map = new HashMap<String, Object>();
        PageInfo<Examine> info = examineService.selectExamine(page, rows,supplierid);
        map.put("total", info.getTotal());
        map.put("rows", info.getList());
        return map;
    }

    @RequestMapping("/insertExamine")
    @ResponseBody
    public ModelAndView insertExamine(String bookname,Integer ISBN,BigDecimal price,String register,BigDecimal groupprice,
    Integer layout,Integer printingnumber,String weight,String bookintroduce,String authorintroduce,String imgurl,HttpSession session){
        ModelAndView mv = new ModelAndView();
        Manager user = (Manager) session.getAttribute("user");
        Integer supplierid = user.getSupplierid();
        Book book =new Book();
        book.setBookname(bookname);
        book.setISBN(ISBN);
        book.setPrice(price);
        book.setRegister(register);
        book.setGroupprice(groupprice);
        book.setLayout(layout);
        book.setPrintingnumber(printingnumber);
        book.setWeight(weight);
        book.setBookintroduce(bookintroduce);
        book.setAuthorintroduce(authorintroduce);
        book.setImgurl(imgurl);
        ActionResult ar = examineService.insertExamine(book,supplierid);
        Integer status = ar.getStatus();

        return mv;
    }

}
